package com.tech.platform.cms.logger.aspect;

import com.tech.platform.cms.logger.annotation.ErrorLog;
import com.tech.platform.cms.logger.publish.ErrorLogPublish;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author shengqiang.wu
 * @date 2020/3/26/026 17:41
 * @desc 异常日志切面用于捕获方法执行是抛出的异常
 */
@Aspect
@Component
public class ErrorLogAspect {

    @Autowired
    private ErrorLogPublish errorLogPublish;

    @AfterThrowing(value = "@annotation(errorLog)",throwing = "ex",argNames = "ex,errorLog")
    public void getErrorLog(JoinPoint point, Throwable ex, ErrorLog errorLog){
        errorLogPublish.publish(errorLog,ex);
    }
}
